/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Prestashop_saver;

import java.io.Serializable;
import java.util.Set;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author strokyl
 */
@Entity
@Table(name = "ps_country")
public class PsCountry implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id_country", nullable = false)
    private Integer idCountry;
    @Basic(optional = false)
    @Column(name = "id_zone", nullable = false)
    private int idZone;
    @Basic(optional = false)
    @Column(name = "id_currency", nullable = false)
    private int idCurrency;
    @Basic(optional = false)
    @Column(name = "iso_code", nullable = false, length = 3)
    private String isoCode;
    @Basic(optional = false)
    @Column(name = "call_prefix", nullable = false)
    private int callPrefix;
    @Basic(optional = false)
    @Column(name = "active", nullable = false)
    private boolean active;
    @Basic(optional = false)
    @Column(name = "contains_states", nullable = false)
    private boolean containsStates;
    @Basic(optional = false)
    @Column(name = "need_identification_number", nullable = false)
    private boolean needIdentificationNumber;
    @Basic(optional = false)
    @Column(name = "need_zip_code", nullable = false)
    private boolean needZipCode;
    @Basic(optional = false)
    @Column(name = "zip_code_format", nullable = false, length = 12)
    private String zipCodeFormat;
    @Basic(optional = false)
    @Column(name = "display_tax_label", nullable = false)
    private boolean displayTaxLabel;

    @OneToMany(fetch=FetchType.EAGER, mappedBy="psCountryLangPK.country")
    private Set<PsCountryLang> countryLangs;

    public PsCountry() {
    }

    public PsCountry(Integer idCountry) {
        this.idCountry = idCountry;
    }

    public PsCountry(Integer idCountry, int idZone, int idCurrency, String isoCode, int callPrefix, boolean active, boolean containsStates, boolean needIdentificationNumber, boolean needZipCode, String zipCodeFormat, boolean displayTaxLabel, Set<PsCountryLang> countryLangs) {
        this.idCountry = idCountry;
        this.idZone = idZone;
        this.idCurrency = idCurrency;
        this.isoCode = isoCode;
        this.callPrefix = callPrefix;
        this.active = active;
        this.containsStates = containsStates;
        this.needIdentificationNumber = needIdentificationNumber;
        this.needZipCode = needZipCode;
        this.zipCodeFormat = zipCodeFormat;
        this.displayTaxLabel = displayTaxLabel;
        this.countryLangs = countryLangs;
    }

    public Integer getIdCountry() {
        return idCountry;
    }

    public void setIdCountry(Integer idCountry) {
        this.idCountry = idCountry;
    }

    public int getIdZone() {
        return idZone;
    }

    public void setIdZone(int idZone) {
        this.idZone = idZone;
    }

    public int getIdCurrency() {
        return idCurrency;
    }

    public void setIdCurrency(int idCurrency) {
        this.idCurrency = idCurrency;
    }

    public String getIsoCode() {
        return isoCode;
    }

    public void setIsoCode(String isoCode) {
        this.isoCode = isoCode;
    }

    public int getCallPrefix() {
        return callPrefix;
    }

    public void setCallPrefix(int callPrefix) {
        this.callPrefix = callPrefix;
    }

    public boolean getActive() {
        return active;
    }

    public String getDefaultCountryName() {
        String result = null;

        for(PsCountryLang countryLang : this.getCountryLangs()) {
            if(countryLang.getPsCountryLangPK().getLang().getIdLang() == PsLang.getDefaultIdLang()) {
                result = countryLang.getName();
                break;
            }
        }

        return result;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    public boolean getContainsStates() {
        return containsStates;
    }

    public void setContainsStates(boolean containsStates) {
        this.containsStates = containsStates;
    }

    public boolean getNeedIdentificationNumber() {
        return needIdentificationNumber;
    }

    public void setNeedIdentificationNumber(boolean needIdentificationNumber) {
        this.needIdentificationNumber = needIdentificationNumber;
    }

    public boolean getNeedZipCode() {
        return needZipCode;
    }

    public void setNeedZipCode(boolean needZipCode) {
        this.needZipCode = needZipCode;
    }

    public String getZipCodeFormat() {
        return zipCodeFormat;
    }

    public void setZipCodeFormat(String zipCodeFormat) {
        this.zipCodeFormat = zipCodeFormat;
    }

    public boolean getDisplayTaxLabel() {
        return displayTaxLabel;
    }

    public void setDisplayTaxLabel(boolean displayTaxLabel) {
        this.displayTaxLabel = displayTaxLabel;
    }

    public Set<PsCountryLang> getCountryLangs() {
        return countryLangs;
    }

    public void setCountryLangs(Set<PsCountryLang> countryLangs) {
        this.countryLangs = countryLangs;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idCountry != null ? idCountry.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof PsCountry)) {
            return false;
        }
        PsCountry other = (PsCountry) object;
        if ((this.idCountry == null && other.idCountry != null) || (this.idCountry != null && !this.idCountry.equals(other.idCountry))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "hibernate.PsCountry[idCountry=" + idCountry + "]";
    }

}
